package com.skysz.nio;

import java.io.IOException;
import java.nio.ByteBuffer;

public class BufferTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		ByteBuffer buf = ByteBuffer.allocate(256);
		while( true ) {
			int c = System.in.read();
			if ( c == -1 ) {
				break;
			}
			buf.put((byte)c);
			if( c == '\n') {
				buf.flip();
				byte[] content = new byte[buf.limit()];
				buf.get(content);
				System.out.println(new String(content));
				buf.clear();
			}
		}
	}

}
